package com.ita.controller;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ita.service.IBookServiceITA;
import com.ita.vo.Book;

@Controller(value="bookControllerITA")
@Scope
@RequestMapping("/bookita")
public class BookControllerITA {

//	private IBookServiceITA service=new BookServiceITAImpl();
//	private IBookServiceITA service=(IBookServiceITA) Contextlistener.ctx.getBean("bookService");

	private IBookServiceITA service;
	
	
	public IBookServiceITA getService() {
		return service;
	}

	@Resource
	public void setService(IBookServiceITA service) {
		this.service = service;
	}

	@RequestMapping(value="/",method=RequestMethod.GET)
	@ResponseBody
	public List<Book> showAll(){
		return service.showAllBook();
	}
	
	@RequestMapping(value="/{bookid}",method=RequestMethod.DELETE)
	@ResponseBody
	public Book delete(@PathVariable String bookid){
		return service.deleteById(bookid);
	}
	@RequestMapping(value="",method=RequestMethod.POST)
	@ResponseBody
	public Book add(Book b){
		return service.insert(b);
	}
}
